package com.apes.fico.finance.model.gl;

import com.apes.fico.masterdata.gl.model.AccountingPeriodItem;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * @program: apestech
 * @description: 损益结转
 * @author: Chengxm
 * @create: 2019-01-21 13:43
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = CarryOverPL.CONST_TABLE_NAME, indexes = {
        @Index(columnList = "year,period_id,company_id", unique = true) } )
public class CarryOverPL extends Model {
    public final static String CONST_TABLE_NAME = "gl_carry_over_pl";

    @Id
    @Column(name = "id", nullable = false, length = 120)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "损益结转", padding = 8)
    @Comment("编号")
    private String id;

    @NotNull
    @Column
    @Comment("会计年度")
    private int year;

    @NotNull
    @Column
    @Comment("会计期间")
    private String period;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "period_id", referencedColumnName = "id", nullable = false)
    @Comment("会计期间")
    private AccountingPeriodItem periodId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id", nullable = false)
    @Comment("公司")
    private PartyRole company;

    @States(name = "状态", values = {
            @State(id = "create", name = "结转损溢"),
            @State(id = "cancel", name = "取消损溢结转"),
            @State(id = "month", name = "月结"),
    })
    @Column(name = "state", length = 30)
    private String state = "create";

    @Comment("状态(0:结转,1:反结转)")
    private int type;

    @Column(name = "monthly_flag", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("月结标记") //0:否 1：是
    private boolean monthlyFlag = false;

}
